package com.faceye.test.util;



public class MySftpConnect {
//    public static void main(String[] args) {
//        MySftpConnect c = new MySftpConnect();
//        c.createSftpClient("192.168.0.108", "szb", "szbpatternx86", 22);－－参数依次为主机名，用户名，密码，端口号。
//    }
//
//    public void createSftpClient(String hostname, String username,
//                                 String password, int port) {
//        try {
//            System.out.println("Connecting to " + hostname);
//
//            // Create an SshConnector instance
//            SshConnector con = SshConnector.getInstance();
//
//            // Connect to the host
//            SocketTransport t = new SocketTransport(hostname, port);
//            t.setTcpNoDelay(true);
//            SshClient ssh = con.connect(t, username);
//            Ssh2Client ssh2 = (Ssh2Client) ssh;
//
//            // Authenticate the user using password authentication
//            com.maverick.ssh.PasswordAuthentication pwd = new com.maverick.ssh.PasswordAuthentication();
//            do {
//                pwd.setPassword(password);
//            } while (ssh2.authenticate(pwd) != SshAuthentication.COMPLETE
//                    && ssh.isConnected());
//            // Start a session and do basic IO
//            if (ssh.isAuthenticated()) {
//                SftpClient sftp = new SftpClient(ssh2);
//                // test create file.
//                this.createTestFile(sftp);
//            }
//        } catch (Throwable th) {
//            th.printStackTrace();
//        }
//    }
//
//    //测试IO操作
//    public void createTestFile(SftpClient sftp) throws Exception {
//
//        File textFile = new File(System.getProperty("user.home"), "shining.txt");
//        FileOutputStream tout = new FileOutputStream(textFile);
//
//        // Create a file with \r\n as EOL
//        for (int i = 0; i < 100; i++) {
//            tout.write("All work and no play makes Jack a dull boy中文\r\n"
//                    .getBytes());
//        }
//        tout.close();
//
//        // Perform some text mode operations指定文件存储为txt类型
//        sftp.setTransferMode(SftpClient.MODE_TEXT);
//
//        // Tell the client which EOL the remote client is using - note
//        // that this will be ignored with version 4 of the protocol
//        sftp.setRemoteEOL(SftpClient.EOL_LF);
//        //将文件上传到服务器
//        sftp.put(textFile.getAbsolutePath());
//    }
}
